package com.xiaoma.tpo.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.xiaoma.tpo.dao.ForumTopicDao;
import com.xiaoma.tpo.domain.ForumTopic;
import com.xiaoma.tpo.dto.ForumTopicVo;

@Controller
@RequestMapping("/share")
public class ShareController {
    
    @Autowired
    private ForumTopicDao topicDao;

    @RequestMapping(value = "/topic/{id}",method = RequestMethod.GET)
    public String topic(@PathVariable int id, Model model){
        ForumTopicVo topicVo = topicDao.findTopic(id);
        List<ForumTopic> topics = topicDao.findTopics(3);
        model.addAttribute("topicVo", topicVo);
        model.addAttribute("topics", topics);
        return "share/p1";
    }
    
    @RequestMapping(value = "/topic/list/{type}",method = RequestMethod.GET)
    public String topicList(@PathVariable int type, Model model){
        List<ForumTopic> topics = topicDao.findTopicsByType(type);
        model.addAttribute("topics", topics);
        return "share/p2";
    }
}
